﻿@model PhoneBilling.Models.GroupMotionModel
@{
    ViewBag.Title = "部组管理";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.async.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.edit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.sortable.js")"></script>
<link href="@Url.Content("~/Content/js/jquery.treeview.css")" rel="stylesheet" type="text/css" />
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    for (int i = 0; i < Model.DepartmentList.Count; i++)
    {
        var department = Model.DepartmentList[i];
        if (i == 0)
        {
            sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Department',ulevel:'0' ", department.名称.Trim(), department.ID));
        }
        else
        {
            sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Department',ulevel:'0' ", department.名称.Trim(), department.ID));
        }

        if (department.分组List.Count > 0)
        {
            sb.Append(",children: [");

            for (int j = 0; j < department.分组List.Count; j++)
            {
                var group1 = department.分组List[j];
                if (j == 0)
                {
                    sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'1' ", group1.名称.Trim(), group1.ID));
                }
                else
                {
                    sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'1' ", group1.名称.Trim(), group1.ID));
                }

                if (group1.分组List.Count > 0)
                {
                    sb.Append(",children: [");

                    for (int k = 0; k < group1.分组List.Count; k++)
                    {
                        var group2 = group1.分组List[k];
                        if (k == 0)
                        {
                            sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'2' ", group2.名称.Trim(), group2.ID));
                        }
                        else
                        {
                            sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'2' ", group2.名称.Trim(), group2.ID));
                        }

                        if (group2.分组List.Count > 0)
                        {
                            sb.Append(",children: [");

                            for (int l = 0; l < group2.分组List.Count; l++)
                            {
                                var group3 = group2.分组List[l];
                                if (l == 0)
                                {
                                    sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'3' ", group3.名称.Trim(), group3.ID));
                                }
                                else
                                {
                                    sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'3' ", group3.名称.Trim(), group3.ID));
                                }

                                sb.AppendLine("}");

                            }

                            sb.Append("]");
                        }

                        sb.AppendLine("}");

                    }

                    sb.Append("]");
                }

                sb.AppendLine("}");

            }

            sb.Append("]");
        }

        sb.AppendLine("}");

    }

    string data = sb.ToString();
}
<script type="text/javascript">
    function selectDepartment(department) {
        $("#target").attr("value", department);

        $("span.file").removeClass("li-active");
        $("span.folder").removeClass("li-active");
        $("span.folder#" + department).addClass("li-active");
    }
    function selectGroup(group) {
        $("#target").attr("value", group);

        $("span.folder").removeClass("li-active");
        $("span.file").removeClass("li-active");
        $("span.file#" + group).addClass("li-active");
    }
</script>
<script type="text/javascript">
      $(document).ready(function () {
          $("#btnConfirm").ligerButton(
        {
            click: function () {
                $('form').submit();
            }
        });
        var tree = $("#tree").ligerTree({ checkbox: false, parentIcon: null, childIcon: null, 
            data: [@Html.Raw(data)]
        ,onClick: function (node) {
            if(isStart == false)
                return false;
            if(node.data.utype == "Department")
            {
                selectDepartment(node.data.uid);
               
            }
            else if(node.data.utype == "group")
            {
                 selectGroup(node.data.uid);
            }
        }
        });
        tree.collapseAll();
      });
    
</script>
@using (Html.BeginForm())
{ 
    <div class="group_motion">
        @Html.ValidationMessageFor(m => m.Target, new { style = "color:Red" })
        <div class="system_input_contain">
            @Html.HiddenFor(m => m.Type)
            @Html.HiddenFor(m => m.Name)
            @Html.HiddenFor(m => m.ID)
            @Html.HiddenFor(m => m.Target, new { id = "target" })
            <strong>要迁移的分组：</strong>
            @Html.DisplayTextFor(m => m.Name)
        </div>
        <div class="system_contain_group">
            <h3 class="title">
                请选择要迁移的目的地</h3>
            <div>
                @Html.ValidationMessageFor(m => m.Target, new { style = "color:Red" })
            </div>
            <div class="system_scroll_container">
                <ul id="tree" />
            </div>
        </div>
    </div>
    
    <div class="system_input_contain">
        <input type="button" id="btnConfirm" value="确定" />
    </div>
}
